package Week_3.E_Mergesort;

/**
 * @author Myhaylo Kotsyuruba
 * @version v.   23.03.13
 */
public class E_Mergesort {

    private static String sData_01 = "81 90 57 69 79 17 43 80 14 39 24 52";

    private static String sData_02 = "19 98 64 93 63 59 97 26 60 17";

    private static String sData_03 = "A (1.0, 4.0)\n" +
            "B (9.0, 9.0)\n" +
            "C (8.0, 1.0)\n" +
            "D (3.0, 2.0)\n" +
            "E (4.0, 0.0)\n" +
            "F (2.0, 5.0)\n" +
            "G (0.0, 7.0)\n" +
            "H (6.0, 3.0)\n" +
            "I (5.0, 6.0)\n" +
            "J (7.0, 8.0)";


    public static void task_01() {
        System.out.println("\n\n\t\tTASK 1");
        String[] numbers = sData_01.split(" ");
        int[] iData_01 = new int[numbers.length];
        for (int i = 0; i < numbers.length; i++) {
            iData_01[i] = Integer.parseInt(numbers[i]);
        }
        print(iData_01);
        Merge.sort(iData_01);
    }

    public static void task_02() {
        System.out.println("\n\n\t\tTASK 2");
        String[] numbers = sData_02.split(" ");
        int[] iData_02  = new int[numbers.length];
        for (int i = 0; i < numbers.length; i++) {
            iData_02[i] = Integer.parseInt(numbers[i]);
        }
        print(iData_02);
        MergeBU.sort(iData_02);
    }

    public static void task_03() {
        System.out.println("\n\n\t\tTASK 3");
        String[] sData = sData_03.split("\n");
        Point2D[] points = new Point2D[sData.length];
        for (int index = 0; index < points.length; index++) {
            points[index] = new Point2D(sData[index]);
        }
        for (Point2D point : points) {
            System.out.print(point + "\t");
        }
        System.out.print("\n");

        GrahamScan myGrahamScan = new GrahamScan(points);
        System.out.println(myGrahamScan.hull());

    }

    public static void run() {
        task_01();
        task_02();
        task_03();
    }

    private static void print(int[] a) {
        String result_01 = "";
        for (int i : a) result_01 += i + " ";
        System.out.println("\t" + result_01);
    }
}
